package com.ttai.ui.activity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.ttai.R;
import com.ttai.dagger.componet.activity.DaggerUserComponet;
import com.ttai.dagger.module.activity.UserPresenterModule;
import com.ttai.presenter.activity.UserPresenter;
import com.ttai.ui.base.BaseActivity;
import com.ttai.ui.other.MessageDialog;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class User extends BaseActivity implements DialogInterface.OnClickListener {
    @Bind(R.id.btn_usercenter)
    Button btnUsercenter;
    @Bind(R.id.btn_over)
    Button btnOver;
    @Inject
    UserPresenter userPresenter;
    @Bind(R.id.btn_feedback)
    Button btnFeedback;
    @Bind(R.id.aboutus)
    Button aboutus;

    MessageDialog messageDialog;


    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        ButterKnife.bind(this);
        setComponet();

        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setBackgroundColor(Color.parseColor("#3399FF"));
        TextView barTitle = (TextView) findViewById(R.id.barTitle);
        barTitle.setText("个人中心");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public void next(View view) {

    }

    @Override
    public void pre(View view) {
        finish();
    }

    @Override
    public void setComponet() {
        DaggerUserComponet.builder()
                .userPresenterModule(new UserPresenterModule(this))
                .build()
                .in(this);
    }

    @OnClick({R.id.btn_usercenter, R.id.btn_over,R.id.btn_feedback,R.id.aboutus})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_usercenter:
                userPresenter.clearTokenAcount();

                this.finish();
                Intent intent = new Intent();
                intent.setClass(User.this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            case R.id.btn_over:
                new AlertDialog.Builder(this)
                        .setMessage("您确定要注销账户？注销后您的所有数据都会被清空")
                        .setIcon(R.drawable.jieshao)
                        .setTitle("注销操作")
                        .setPositiveButton("确定", this)
                        .setNegativeButton("取消", this)
                        .show();
                break;
            case R.id.btn_feedback:
                messageDialog = new MessageDialog(this);
                messageDialog.setTitle("提示");
                messageDialog.setMessage("还有个小功能，点击个人中心“意见反馈”，弹个窗写：“请告诉我们您对“态安全”的意见与建议，我们会参考您的反馈不断优化我们的产品。\n邮箱：ttai_tech@163.com”");
                messageDialog.setYesOnclickListener("好的", new MessageDialog.onYesOnclickListener() {
                    @Override
                    public void onYesClick() {
                        messageDialog.dismiss();
                    }
                });
                messageDialog.setNoOnclickListener("取消", new MessageDialog.onNoOnclickListener() {
                    @Override
                    public void onNoClick() {
                        messageDialog.dismiss();
                    }
                });
                messageDialog.show();

        }
    }

    @Override
    public void onClick(DialogInterface dialogInterface, int which) {
        if (which == DialogInterface.BUTTON_POSITIVE) {
            String token = userPresenter.getToken();
            userPresenter.logOut(token);
        } else if (which == DialogInterface.BUTTON_NEGATIVE) {
        }
    }
}
